python custom array sort

104

python custom array sort -

>>> sorted(pokemon, key=lambda x: x[2])		# sort by attack power, by this way
>>> pokemon.sort(key=lambda x: x[2])		# or by this way
#Date is like this
[('Charmander', 'Fire', 52),
 ('Blastoise', 'Water', 83),
 ('Beedrill', 'Poison', 90)]

python sort list by custom function -

from functools import cmp_to_key
sorted(mylist, key=cmp_to_key(lambda item1, item2: fitness(item1) - fitness(item2)))

Comments

Submit
0 Comments